import http from "@/api";

export namespace Factory {
  export interface FactoryListItem {
    id: number;
    factoryCode: string;
    factoryName: string;
    address: string;
    phone: string;
    manager: string;
    status: string;
    description: string;
    createdBy: string;
    createdTime: string;
    updatedBy: string;
    updatedTime: string;
    deleted: number;
  }

  export interface CreateFactoryReq {
    factoryCode: string;
    factoryName: string;
    address?: string;
    phone?: string;
    manager?: string;
    description?: string;
  }

  export interface UpdateFactoryReq {
    factoryName: string;
    address?: string;
    phone?: string;
    manager?: string;
    description?: string;
  }
}

/**
 * @name 工厂管理模块
 */
// 获取工厂列表
export const getFactoryList = (params: any) => {
  return http.get<any>(`/factories/page`, params);
};

// 根据ID获取工厂详情
export const getFactoryById = (id: number) => {
  return http.get<Factory.FactoryListItem>(`/factories/${id}`);
};

// 根据状态获取工厂列表
export const getFactoryByStatus = (params: any, status: string) => {
  return http.get<any>(`/factories/status/${status}`, params);
};

// 创建工厂
export const createFactory = (params: Factory.CreateFactoryReq) => {
  return http.post<number>(`/factories`, params);
};

// 更新工厂
export const updateFactory = (id: number, params: Factory.UpdateFactoryReq) => {
  return http.put(`/factories/${id}`, params);
};

// 启用工厂
export const enableFactory = (id: number) => {
  return http.post(`/factories/${id}/enable`);
};

// 禁用工厂
export const disableFactory = (id: number) => {
  return http.post(`/factories/${id}/disable`);
};

// 删除工厂
export const deleteFactory = (id: number) => {
  return http.delete(`/factories/${id}`);
};
